Skip to content

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Apr 5, 2024

The current Optional.construct returns nil when the given JS value is null or undefined, but nilmeans a failure during decode here, so it's semantically wrong. Instead, it should return.some(nil)`.

Also, when Wrapped.construct returns nil, it means decode operation failed, so Optional.construct method should return nil. But it might be unclear that the returned Optional<Wrapped> value won't be implicitly casted to .some(nil), so I changed to return nil by guard statement explicitly.

Original description

現在の実装ではJSの値として null, undefined の場合に、
Optional.constructnil を返していますが、
これはデコードの失敗を意味するため間違っています。

適切に Optional.none がデコードできた状況なので、 .some(nil) を返す必要があります。

また、 Wrapped.constructnil を返した場合は、
デコード失敗なので nil を返すべきですが、
ここで暗黙のキャストによって .some(nil) が返ってしまうかどうか分かりづらいと思ったので、
明示的に guard 文で分岐するように書き換えてみました。

@kateinoigakukun kateinoigakukun merged commit 32538ec into swiftwasm:main Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants